﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using BusinessLayer;
using CustomerServiceCenter.Helper;
using System.Web;
using BusinessLayer.DatabaseEntities;
using CustomerServiceCenter.Models;

namespace CustomerServiceCenter.Controllers.API
{
    public class HomeController : ApiController
    {
        [LoginAuthorize]
        public string modifyPassword(ModifyPasswordModel model) {
            try
            {
                var loginInfo = HttpContext.Current.Session["adminLoginInfo"] as Operator;
                Operator operatorInfo = AdminBusiness.FindOperator(loginInfo.ID, model.OldPassword);
                if (null == model.OldPassword)
                {
                    return "原密码不能为空";
                }

                if (null == model.NewPassword)
                {
                    return "新密码不能为空";
                }
                if (!model.NewPassword.Equals(model.ConfirmPassword))
                {
                    return "两次密码填写不一致";
                }
                if (null == operatorInfo)
                {
                    return "原密码填写错误";
                }

                AdminBusiness.ResetPassword(loginInfo.ID, model.NewPassword, model.OldPassword);
                return null;
            }
            catch (Exception)
            {
                return "密码修改失败";
                //throw;
            }
        }


    }
}
